package com.benshou.bcss.common.j17common;

import lombok.NonNull;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collector;

/**
 * @author <a href="mailto:wh1zper@qq.com">wh1zper</a>
 */
public class CollectorX {

    public static <T, K> Collector<T, ?, Map<K, T>> toUniqueKeyMap(
            @NonNull Function<? super T, ? extends K> keyMapper) {
        return Collector.of(
                HashMap::new,
                Means.uniqKeysMapAccumulator(keyMapper, Function.identity()),
                Means.uniqKeysMapMerger());
    }

    public static <E extends Map.Entry<? extends K, ? extends V>, K, V> Collector<E, ?, Map<K, V>> toEntryMap() {
        return Collector.of(
                HashMap::new,
                Means.uniqKeysMapAccumulator(
                        Map.Entry::getKey,
                        Map.Entry::getValue),
                Means.uniqKeysMapMerger());
    }
}
